package com.xingda.packing.config.appset;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * 加载配置文件
 */
@Configuration
@Slf4j
public class AppSetConfig {
    @Value("${com.xingda.config.version}")
    @Getter
    private String version;

    @Bean
    public AppSetPLC readPLC() throws IOException {
        return new ObjectMapper().readValue(this.getClass().getResourceAsStream("/appset_config_" + version + "/appset-plc-config.json"), AppSetPLC.class);
    }

    @Bean
    public AppSetRule readRule() throws IOException {
        return new ObjectMapper().readValue(this.getClass().getResourceAsStream("/appset_config_" + version + "/appset-rule-config.json"), AppSetRule.class);
    }

    @Bean
    public AppSetParam readParam() throws IOException {
        return new ObjectMapper().readValue(this.getClass().getResourceAsStream("/appset_config_" + version + "/appset-param-config.json"), AppSetParam.class);
    }

    @Bean
    public AppSetUrl readUrl() throws IOException {
        return new ObjectMapper().readValue(this.getClass().getResourceAsStream("/appset_config_" + version + "/appset-url-config.json"), AppSetUrl.class);
    }
}
